XML Attributes


An attribute is a property of an element. Attributes are expressed as information within an element's start tag (or in an empty-element tag). For example,

<plant zone=3>   <common>Columbine</common>   <botanical>Aquilegia canadensis</botanical></plant>

Notice that the 'zone' attribute in the opening <plant> tag is formatted as a name=value pair, where name is the name (case-sensitive) of the attribute, and pair is the value for this instance of the element. You can use one of these two formats:

attribute_name="attribute_value"
attribute_name='attribute_value'

Attributes provide a method of associating values with an element without making the attributes a part of the content of that element. Deciding whether information should be stored in an attribute or element can be confusing, since it is easy to create child elements for finer granularity in your data. A rule of thumb is to store information in an attribute if the information describes the element. Information that provides the actual data should be part of the element content.

NOTE: Attribute values can be any ASCII characters, including those normally reserved for markup. Because they were not designed to be parsable, attribute values cannot be validated. The parser will check to determine that an attribute name and value match the type declared in the document's schema, but the parser doesn't care what the value is.

Copyright 2000 Extensibility, Inc.

Suite 250, 200 Franklin Street, Chapel Hill, North Carolina 27516